package com.sh.data.engine.common.enumDefinition;

import com.google.common.collect.Lists;

import java.util.List;
import java.util.Objects;

/**
 * @author: zigui.zdf
 * @description:
 * @date: 2021/6/3 14:42
 */
public enum FlinkNodeTypeEnum {
    //  FLINK_SQL_TASK(0, "flinkSqlTask"),
    //  FLINK_TASK(1, "flinkTask"),
    //  FLINK_DATA_SYNC_TASK(2, "flinkDataSyncTask"),
    //  UDF_FUNCTION(3, "udf函数"),
    //  UDAF_FUNCTION(4, "udaf函数"),
    //  UDTF_FUNCTION(5, "udtf函数"),
    //  RESOURCE(6, "资源"),
    //  ;
    DIR(0, "目录"),
    TASK_SQL(1, "sql任务"),
    TASK_SQL_GUIDE(2, "sql任务向导模式"),
    TASK_JAR(3, "jar任务"),
    FUNCTION(4, "函数"),
    RESOURCE(5, "资源");

    int code;

    String name;

    FlinkNodeTypeEnum(int code, String name) {
        this.code = code;
        this.name = name;
    }

    public int getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public static boolean isFunctionNode(Integer nodeType) {
        //    List<Integer> functionNodes =
        //        Lists.newArrayList(
        //            UDF_FUNCTION.getCode(), UDAF_FUNCTION.getCode(), UDTF_FUNCTION.getCode());
        List<Integer> functionNodes = Lists.newArrayList(FUNCTION.getCode());
        return functionNodes.contains(nodeType);
    }

    public static FlinkNodeTypeEnum getByNodeType(Integer nodeType) {
        for (FlinkNodeTypeEnum typeEnum : FlinkNodeTypeEnum.values()) {
            if (Objects.equals(typeEnum.getCode(), nodeType)) {
                return typeEnum;
            }
        }
        return null;
    }

    public static List<Integer> getAllFunctionNodeTypeList() {
        //    List<Integer> nodeTypes =
        //        Lists.newArrayList(UDF_FUNCTION.code, UDAF_FUNCTION.code, UDTF_FUNCTION.code);
        List<Integer> nodeTypes = Lists.newArrayList(FUNCTION.getCode());
        return nodeTypes;
    }
}
